﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;

namespace WinFormsApp1.Leo.week02
{
    public partial class SlaughteredAdd : Form
    {
        public SlaughteredAdd()
        {
            InitializeComponent();
            GetUPCData();
            GetWaiting();
            GetLive();
        }

        private record Supplier();


        //商品代号
        public async void GetUPCData()
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<UPCDataser>>>(URLCommon.Url2, "/WeekListOne_Leo/GetUPCDataShow", HttpClientHelper.MethodType.GET, default);

            comboBox1.DataSource = items.Data;
            comboBox1.DisplayMember = "UPCDataName";
            comboBox1.ValueMember = "GoodsMinuteId";

            this.Controls.Add(comboBox1);
        }

        public class UPCDataser
        {
            public int GoodsMinuteId { get; set; }
            public string UPCDataName { get; set; }
        }


        //活畜单号
        public async void GetLive()
        {

            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<LiveAnimakses>>>(URLCommon.Url2, "/WeekListOne_Leo/GeLiveAnimalsShow2", HttpClientHelper.MethodType.GET, default);

            comboBox2.DataSource = items.Data;
            comboBox2.DisplayMember = "LiveAnimalsDocument";
            comboBox2.ValueMember = "LiveAnimalsId";

        }

        public class LiveAnimakses
        {
            public int LiveAnimalsId { get; set; }
            /// <summary>
            /// 单据号
            /// </summary>
            public string LiveAnimalsDocument { get; set; }
        }

        //待宰圈号
        public async void GetWaiting()
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<Waitingss>>>(URLCommon.Url2, "/WeekListOne_Leo/GeWaitingShow", HttpClientHelper.MethodType.GET, default);

            comboBox3.DataSource = items.Data;
            comboBox3.DisplayMember = "WaitingName";
            comboBox3.ValueMember = "WaitingId";

            this.Controls.Add(comboBox1);
        }

        public class Waitingss
        {
            public int WaitingId { get; set; }
            public string WaitingName { get; set; }
        }

        public record Slaughteredse(int MarkId, int LiveAnimalsId, int WaitingId, DateTime slaughteredTime, string slaughteredRemark, bool isDelete);

        //添加
        private async void button1_Click(object sender, EventArgs e)
        {

            var checkInId = Convert.ToInt32(comboBox1.SelectedValue);
            var LiveAnimalsId = Convert.ToInt32(comboBox2.SelectedValue);
            var markId = Convert.ToInt32(comboBox3.SelectedValue);
            var slaughteredTime = Convert.ToDateTime(dateTimePicker1.Text);
            var slaughteredRemark = textBox6.Text;
            var isDelete = false;



            Slaughteredse clients = new(checkInId, LiveAnimalsId, markId, slaughteredTime, slaughteredRemark, isDelete);
            var res = await HttpClientHelper.RequestUrl<Slaughteredse, ApiResult<Slaughteredtes>>(URLCommon.Url1, "/WorkList01_leo/GetSlaugAdd", HttpClientHelper.MethodType.POST, clients);
            if (res.Code == 1)
            {
                MessageBox.Show("添加成功");
            }
        }

        public class Slaughteredtes
        {
            public int SlaughteredId { get; set; }

            /// <summary>
            /// 商品代号(外键)
            /// </summary>
            public int MarkId { get; set; }


            /// <summary>
            /// 活畜id
            /// </summary>
            public int LiveAnimalsId { get; set; }

            /// <summary>
            /// 待宰圈号（外键）
            /// </summary>
            public int WaitingId { get; set; }

            /// <summary>
            /// 入圈时间
            /// </summary>
            public DateTime? SlaughteredTime { get; set; }

            /// <summary>
            /// 备注
            /// </summary>
            public string SlaughteredRemark { get; set; }

            /// <summary>
            /// 是否删除
            /// </summary>
            public bool IsDelete { get; set; } = false;
        }

        private void SlaughteredAdd_Load(object sender, EventArgs e)
        {

        }
    }
}
